import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'


export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '首页', icon: 'index' }
    }]
  },
  // 用户管理
  {
    path: '/user',
    component: Layout,
    redirect: '/user/table',
    name: '用户管理',
    meta: { title: '用户管理', icon: 'example' },
    children: [
      {
        path: 'table',
        name: '用户列表',
        component: () => import('@/views/edu/user/list'),
        meta: { title: '用户列表' }
      },
      {
        path: 'save',
        name: '添加讲师',
        component: () => import('@/views/edu/user/save'),
        meta: { title: '添加讲师' }
      },
    ]
  },
  // 首页管理
  {
    path: '/banner',
    component: Layout,
    redirect: '/banner/table',
    name: '首页管理',
    meta: { title: '首页管理', icon: 'example' },
    children: [
      {
        path: 'table',
        name: '轮播图列表',
        component: () => import('@/views/edu/banner/list'),
        meta: { title: '轮播图列表' }
      },
      {
        path: 'save',
        name: '添加轮播图',
        component: () => import('@/views/edu/banner/save'),
        meta: { title: '添加轮播图'}
      },
      {
        path: 'save/:id',
        name: '编辑轮播图',
        component: () => import('@/views/edu/banner/save'),
        meta: { title: '编辑轮播图', noCache: true },
        hidden: true
      }
    ]
  },
  // 讲师管理路由
  {
    path: '/teacher',
    component: Layout,
    redirect: '/teacher/table',
    name: '讲师管理',
    meta: { title: '讲师管理', icon: 'example' },
    children: [
      {
        path: 'table',
        name: '讲师列表',
        component: () => import('@/views/edu/teacher/list'),
        meta: { title: '讲师列表' }
      },
      {
        path: 'save',
        name: '添加讲师',
        component: () => import('@/views/edu/teacher/save'),
        meta: { title: '添加讲师' }
      },
      {
        path: 'save/:id',
        name: '编辑讲师',
        component: () => import('@/views/edu/teacher/save'),
        meta: { title: '编辑讲师', noCache: true },
        hidden: true
      }
    ]
  },
  // ---
  // 课程管理路由
  {
    path: '/subject',
    component: Layout,
    redirect: '/subject/list',
    name: '课程管理',
    meta: { title: '课程管理', icon: 'example' },
    children: [
      {
        path: 'subject_table',
        name: '课程分类列表',
        component: () => import('@/views/edu/subject/list'),
        meta: { title: '课程分类列表' }
      },
      {
        path: 'course_table',
        name: '课程列表',
        component: () => import('@/views/edu/course/list'),
        meta: { title: '课程列表' }
      },
      {
        path: 'course_save',
        name: '添加课程',
        component: () => import('@/views/edu/course/info'),
        meta: { title: '添加课程'}
      },
      {
        path: 'info/:id',
        name: 'EduCourseInfoEdit',
        component: () => import('@/views/edu/course/info'),
        meta: { title: '编辑课程基本信息', noCache: true },
        hidden: true
      },
      {
        path: 'chapter/:id',
        name: 'EduCourseChapterEdit',
        component: () => import('@/views/edu/course/chapter'),
        meta: { title: '编辑课程大纲', noCache: true },
        hidden: true
      },
      {
        path: 'publish/:id',
        name: 'EduCoursePublishEdit',
        component: () => import('@/views/edu/course/publish'),
        meta: { title: '发布课程', noCache: true },
        hidden: true
      }

    ]
  },
  {
    path: '/user',
    component: Layout,
    redirect: '/user/table',
    name: '文章管理',
    meta: { title: '文章管理', icon: 'example' },
    children: [
      {
        path: 'table',
        name: '用户列表',
        component: () => import('@/views/edu/user/list'),
        meta: { title: '用户列表' }
      },
      {
        path: 'save',
        name: '添加讲师',
        component: () => import('@/views/edu/user/save'),
        meta: { title: '添加讲师' }
      },
    ]
  },
  {
    path: '/user',
    component: Layout,
    redirect: '/user/table',
    name: '评论管理',
    meta: { title: '评论管理', icon: 'example' },
    children: [
      {
        path: 'table',
        name: '评论列表',
        component: () => import('@/views/edu/user/list'),
        meta: { title: '用户列表' }
      },
      {
        path: 'save',
        name: '添加讲师',
        component: () => import('@/views/edu/user/save'),
        meta: { title: '添加讲师' }
      },
    ]
  },
  {
    path: '/user',
    component: Layout,
    redirect: '/user/table',
    name: '订单管理',
    meta: { title: '订单管理', icon: 'example' },
    children: [
      {
        path: 'table',
        name: '用户列表',
        component: () => import('@/views/edu/user/list'),
        meta: { title: '用户列表' }
      },
      {
        path: 'save',
        name: '添加讲师',
        component: () => import('@/views/edu/user/save'),
        meta: { title: '添加讲师' }
      },
    ]
  },
  {
    path: '/user',
    component: Layout,
    redirect: '/user/table',
    name: '题目管理',
    meta: { title: '题目管理', icon: 'example' },
    children: [
      {
        path: 'table',
        name: '题目列表',
        component: () => import('@/views/edu/user/list'),
        meta: { title: '用户列表' }
      },
      {
        path: 'save',
        name: '添加题目',
        component: () => import('@/views/edu/user/save'),
        meta: { title: '添加题目' }
      },
    ]
  },
  {
    path: '/user',
    component: Layout,
    redirect: '/user/table',
    name: '资源管理',
    meta: { title: '资源管理', icon: 'example' },
    children: [
      {
        path: 'table',
        name: '用户列表',
        component: () => import('@/views/edu/user/list'),
        meta: { title: '用户列表' }
      },
      {
        path: 'save',
        name: '添加讲师',
        component: () => import('@/views/edu/user/save'),
        meta: { title: '添加讲师' }
      },
    ]
  },
  // -------
  // {
  //   path: '/example',
  //   component: Layout,
  //   redirect: '/example/table',
  //   name: 'Example',
  //   meta: { title: 'Example', icon: 'el-icon-s-help' },
  //   children: [
  //     {
  //       path: 'table',
  //       name: 'Table',
  //       component: () => import('@/views/table/index'),
  //       meta: { title: 'Table', icon: 'table' }
  //     },
  //     {
  //       path: 'tree',
  //       name: 'Tree',
  //       component: () => import('@/views/tree/index'),
  //       meta: { title: 'Tree', icon: 'tree' }
  //     }
  //   ]
  // },

  // {
  //   path: '/form',
  //   component: Layout,
  //   children: [
  //     {
  //       path: 'index',
  //       name: 'Form',
  //       component: () => import('@/views/form/index'),
  //       meta: { title: 'Form', icon: 'form' }
  //     }
  //   ]
  // },

  // {
  //   path: '/nested',
  //   component: Layout,
  //   redirect: '/nested/menu1',
  //   name: 'Nested',
  //   meta: {
  //     title: 'Nested',
  //     icon: 'nested'
  //   },
  //   children: [
  //     {
  //       path: 'menu1',
  //       component: () => import('@/views/nested/menu1/index'), // Parent router-view
  //       name: 'Menu1',
  //       meta: { title: 'Menu1' },
  //       children: [
  //         {
  //           path: 'menu1-1',
  //           component: () => import('@/views/nested/menu1/menu1-1'),
  //           name: 'Menu1-1',
  //           meta: { title: 'Menu1-1' }
  //         },
  //         {
  //           path: 'menu1-2',
  //           component: () => import('@/views/nested/menu1/menu1-2'),
  //           name: 'Menu1-2',
  //           meta: { title: 'Menu1-2' },
  //           children: [
  //             {
  //               path: 'menu1-2-1',
  //               component: () => import('@/views/nested/menu1/menu1-2/menu1-2-1'),
  //               name: 'Menu1-2-1',
  //               meta: { title: 'Menu1-2-1' }
  //             },
  //             {
  //               path: 'menu1-2-2',
  //               component: () => import('@/views/nested/menu1/menu1-2/menu1-2-2'),
  //               name: 'Menu1-2-2',
  //               meta: { title: 'Menu1-2-2' }
  //             }
  //           ]
  //         },
  //         {
  //           path: 'menu1-3',
  //           component: () => import('@/views/nested/menu1/menu1-3'),
  //           name: 'Menu1-3',
  //           meta: { title: 'Menu1-3' }
  //         }
  //       ]
  //     },
  //     {
  //       path: 'menu2',
  //       component: () => import('@/views/nested/menu2/index'),
  //       name: 'Menu2',
  //       meta: { title: 'menu2' }
  //     }
  //   ]
  // },

  {
    path: 'external-link',
    component: Layout,
    children: [
      {
        path: 'https://panjiachen.github.io/vue-element-admin-site/#/',
        meta: { title: '退出系统', icon: 'link' }
      }
    ]
  },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
